#include "../TcpClass.h"

int main()
{
	char filename[70];
    TcpServer ts;
    initTcpServer(&ts,"0.0.0.0",9999,5);
	while(1)
	{
		TcpSocket tsock;
		TcpServAccept(&ts,&tsock);
		TcpSockRecv(&tsock,filename,sizeof(filename));
		printf("%s\n",filename);
		int file_fd = open(filename,O_RDWR|O_CREAT);
		printf("%d\n",file_fd);
		char buffer[1024];
		int size;
		unsigned long long sum = 0;
		while((size = TcpSockRecv(&tsock,buffer,sizeof(buffer))) > 0)
		{
			sum+=size;
			printf("size: %d\n",size);
			write(file_fd,buffer,size);
		}
		printf("sum: %llu\n",sum);
		TcpSockClose(&tsock);
		close(file_fd);
		printf("transport success\n");
	}
	TcpServClose(&ts);
    return 0;
}
